package com.socketest;

import java.io.*;
import java.net.Socket;

public class ServerThread extends Thread{

    private Socket socket;
    public ServerThread(Socket socket){
        this.socket = socket;
    }
    BufferedReader br = null;
    @Override
    public void run() {
        String str = null;
        try {
            br = new BufferedReader(new InputStreamReader( socket.getInputStream()));
            //
            BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            while (!(str=br.readLine()).equals("exit")){
                System.out.println("客户端说："+str);

                bw.write("服务端收到客户端信息："+str);
                bw.newLine();
                bw.flush();

            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

